<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <script src="js/jquery-1.11.0.min.js"></script>
</head>
<body>

<form>
    username:<input type="text" id="username"> <br>
    password:<input type="password" id="password"> <br>

    <input type="button" value="登录" id="login">
</form>
<script>
    $("#login").click(function (){
        //获取用户输入的用户名密码，发送异步请求实现登录
        let username = $("#username").val();
        let password = $("#password").val();

        let params = {
            username:username,
            password:password
        }

        //发送异步请求
        $.ajax({
            url:"/user/login",
            type:"post",
            data:JSON.stringify(params),
            contentType:"application/json",
            success:function (r){
                let code = r.code;
                if (code == 1000){
                    //成功
                    location.href = "index.html"
                }else{
                    //失败
                    alert(r.msg)
                }
            },
            dataType:"json"
        })
    });

</script>
</body>
</html>